package com.example.himalayaproject.subscription.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.himalayaproject.R;
import com.example.himalayaproject.subscription.activity.BaseSpecialActivity;
import com.example.himalayaproject.subscription.bean.detailsentity.DateEntity;
import com.squareup.picasso.Picasso;

import java.text.DecimalFormat;

/**
 * Created by Administrator on 2016/12/12.
 */
public class FragmentSepcialDetailsAdapterItem3Adapter extends RecyclerView.Adapter<FragmentSepcialDetailsAdapterItem3Adapter.ViewHolder>{
   private   DateEntity date;
   private Context context;
    private String counts = "";

    public FragmentSepcialDetailsAdapterItem3Adapter(Context context,DateEntity date) {
        this.date = date;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.fragment_special_item3,parent,false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.title1.setText(date.getRecs().getList().get(position).getTitle());
        holder.title2.setText(date.getRecs().getList().get(position).getIntro());
        DecimalFormat decimalFormat = new DecimalFormat(".0");
        double number = Integer.parseInt(date.getRecs().getList().get(position).getPlaysCounts()) / 10000;
        if (number > 9999) {
            number = number / 10000;
            holder.lookNumber.setText(decimalFormat.format(number) + "亿");
            counts = holder.lookNumber.getText().toString();
        } else {
            holder.lookNumber.setText(decimalFormat.format(number) + "万");
            counts = holder.lookNumber.getText().toString();
        }
        holder.tvNumber.setText(date.getRecs().getList().get(position).getTracks() + "集");
        Picasso.with(context).load(date.getRecs().getList().get(position).getCoverSmall()).into(holder.imageView);
        holder.linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BaseSpecialActivity.class);
                intent.putExtra("imageUrl",date.getRecs().getList().get(position).getCoverMiddle());
                intent.putExtra("playCounts",counts);
                intent.putExtra("title",date.getUser().getNickname());
                intent.putExtra("albumId", date.getRecs().getList().get(position).getAlbumId());
                Log.d("1630",date.getRecs().getList().get(position).getTracks()+"ab");
                intent.putExtra("number",date.getRecs().getList().get(position).getTracks());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 3;
    }

    public  static  class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView title1, title2, lookNumber, tvNumber;
        private LinearLayout linearLayout;
        public ViewHolder(View itemView) {
            super(itemView);
            title1 = (TextView) itemView.findViewById(R.id.fragment_special_item3_title1);
            title2 = (TextView) itemView.findViewById(R.id.fragment_special_item3_title2);
            lookNumber = (TextView) itemView.findViewById(R.id.fragment_special_item3_looker_number);
            tvNumber = (TextView) itemView.findViewById(R.id.fragment_special_item3_tv_number);
            imageView = (ImageView) itemView.findViewById(R.id.fragment_special_item3_image);
            linearLayout = (LinearLayout) itemView.findViewById(R.id.fragment_special_item3_linearlayout);
        }
    }
}
